import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


public class DatabaseDumper {
	 public static void main(String[] args) throws Exception {
		SQLiteDatabase db = new SQLiteDatabase();
		ResultSet rs = null;
		try {
			Statement s = db.connect("chat_server");
			
			System.out.println("USERS");
			System.out.println("------------------------");
			rs = s.executeQuery("SELECT * FROM Users WHERE 1;");
			printTable(rs);
			
			System.out.println();
			System.out.println("FRIENDS");
			System.out.println("------------------------");
			
			rs = s.executeQuery("SELECT * FROM Friends WHERE 1;");
			printTable(rs);
			
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	private static void printTable(ResultSet rs) throws SQLException {
		String ln = "";
		ResultSetMetaData meta = rs.getMetaData();
		while(rs.next()) {
			for(int i=1; i<=meta.getColumnCount(); ++i)
				ln += "| " + rs.getString(i) + " |";
			System.out.println(ln);
			ln = "";
		}
	}
}
